<?php

namespace app\common\form;


/**
 * 系统配置表单字段
 */
class ConfigInputField
{


    /**
     * 配置名称
     * @var string
     */
    protected string $name;

    /**
     * 配置标题
     * @var string
     */
    protected string $title;

    /**
     * 配置标题
     * @var string
     */
    protected string $group;

    /**
     * 输入提示
     * @var string
     */
    protected string $tip;

    /**
     * 输入类型
     * @var string
     */
    protected string $type;


    /**
     * 配置值
     * @var string
     */
    protected string $value;

    /**
     * 附加属性
     * @var string|array
     */
    protected string|array $content;

    /**
     * 验证规则
     * @var string
     */
    protected string $rule;


    /**
     * 扩展属性
     * @var string
     */
    protected string $extend;


    /**
     * 排序权重
     * @var int
     */
    protected int $weigh = 0;


    /**
     * 初始化函数
     * @param string $group
     * @param string $name
     * @param string $title
     */
    public function __construct(string $group, string $name, string $title)
    {
        $this->name = $name;
        $this->title = $title;
        $this->group = $group;
        return $this;
    }


    public function setTip(string $tip)
    {
        $this->tip = $tip;
        return $this;
    }


    public function setType(string $type)
    {
        $this->type = $type;
        return $this;
    }


    public function setValue(string $value)
    {
        $this->value = $value;
        return $this;
    }


    public function setContent(array|string $content)
    {
        $this->content = $content;
        return $this;
    }


    public function setRule(string $rule)
    {
        $this->rule = $rule;
        return $this;
    }


    public function setExtend(string $extend)
    {
        $this->extend = $extend;
        return $this;
    }


    public function setWeigh(int $weigh)
    {
        $this->weigh = $weigh;
        return $this;
    }


    /**
     * 获取数组
     * @return array
     */
    public function toArray(): array
    {
        return [
            'name' => $this->name,
            'title' => $this->title,
            'group' => $this->group,
            'tip' => $this->tip,
            'type' => $this->type,
            'value' => $this->value ?? '',
            'content' => $this->content ?? [],
            'rule' => $this->rule ?? '',
            'extend' => $this->extend ?? '',
            'var_name' => $this->group . '.' . $this->name,
            'weigh'    => $this->weigh
        ];
    }






}